package com.df.tv.launcher.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.df.tv.launcher.R;
import com.df.tv.launcher.entity.SettingBean;

public class SettingAdapter extends BaseAdapter {
    private List<SettingBean> mSettingList = new ArrayList<SettingBean>();
    private Context mContext;

    public SettingAdapter(Context context, List<SettingBean> list) {
        this.mContext = context;
        this.mSettingList = list;
    }

    @Override
    public int getCount() {
        return mSettingList.size();
    }

    @Override
    public Object getItem(int position) {
        return mSettingList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.setting_griditem, null);
            holder.settingIcon = (ImageView) convertView.findViewById(R.id.img_setting);
            holder.title = (TextView) convertView.findViewById(R.id.tv_title_name);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.settingIcon.setBackgroundResource(mSettingList.get(position).getResId());
        holder.title.setText(mSettingList.get(position).getName());
        return convertView;
    }

    private static class ViewHolder {
        private TextView title;
        private ImageView settingIcon;
    }

}
